{% extends "skeleton.html" %}
{% import "forum/macros.html" as m %}

{% block header %}
  {{m.html_header(resource_version)}}
{% endblock %}
{% block pagetitle %}Forums &bull; {{forum.name}}{% endblock %}
{% block title %}Forums &bull; {{forum.name}}{% endblock %}

{% macro thread_entry(thread, first_posts, last_posts, post_counts, profiles) -%}
  <div class="thread-entry">
    <div class="thread-title">
      <div class="thread-title-link"><a href="/forum/{{forum.slug}}/{{thread.slug}}">{{thread.subject}}</a></div>
      <div>{{first_posts[thread.key()].content|striptags|truncate(100)}}</div>
    </div>
    <div class="thread-replycount">
      <div><span>{{post_counts[thread.forum.slug+":"+thread.slug] - 1}}</span> replies</div>
    </div>
    <div class="thread-details">
      <div class="thread-author">started by <a href="{{m.profile_url(profiles[thread.user.user_id()])}}"><img src="{{profiles[thread.user.user_id()]|profile_shield}}" width="16" height="16"/> {{profiles[thread.user.user_id()].display_name}}</a></div>
      <div class="lastpost-author">last reply by <a href="{{m.profile_url(profiles[last_posts[thread.key()].user.user_id()])}}"><img src="{{profiles[last_posts[thread.key()].user.user_id()]|profile_shield}}" width="16" height="16"/> {{profiles[last_posts[thread.key()].user.user_id()].display_name}}</a></div>
      <div class="lastpost-date"><time datetime="{{last_posts[thread.key()]|post_date_std}}" class="post-date">{{last_posts[thread.key()]|post_date_time}}</time></div>
    </div>
    <div class="last"></div>
  </div>
{%- endmacro %}

{% block maincontent %}
  <section class="content">
    <nav class="breadcrumbs">
      <ul>
        <li><a href="/">War Worlds</a>
        <li><a href="/forum">Forums</a>
        <li><span>{{forum.name}}</span>
      </ul>
    </nav>

  <nav class="toolbar">
    <ul>
    {% if can_post %}
      <li><a href="/forum/{{forum.slug}}/posts" class="button">New Post</a></li>
    {% endif %}
    {% if is_moderator -%}
       <!-- You're a moderator! -->
    {% endif %}
      <li class="search">
        <form action="/forum/search" method="get">
          <input type="text" name="q" placeholder="Search">
          <input type="hidden" name="forum" value="{{forum.slug}}" />
          <div class="input-button"><input type="submit" value="Search"></div>
        </form>
      </li>
    </ul>
  </nav>

  <div class="sticky-threads">
    {% for thread in sticky_threads if thread.key() in last_posts %}
      {{thread_entry(thread, first_posts, last_posts, post_counts, profiles)}}
    {% endfor %}
  </div>

  {% for thread in threads if thread.key() in last_posts %}
    {{thread_entry(thread, first_posts, last_posts, post_counts, profiles)}}
  {% endfor %}

    {{m.paginator(page_no, total_pages)}}
  </section>
{% endblock %}
